<?
include_once("includes/header.php");
$tipoInforme = "";
$numeroProtocolo = "";
if (isset($_SESSION["idTipoInforme"]))
{
    $idTipoInforme = is_numeric($_SESSION["idTipoInforme"]) ? $_SESSION["idTipoInforme"] : 0;
    $link = OpenDB();
    $query = "select descripcion from tipo_informe where id_tipo_informe =" . $idTipoInforme;
    $tipoInforme = GetSQLFirstValue($query);
}
if (isset($_SESSION["protocolo"]))
{
    $numeroProtocolo = $_SESSION["protocolo"];
}

$step = "";
if (isset($_GET["step"]))
    $step = $_GET["step"];


$codigo = "";
if (isset($_GET["codigo"]))
    $codigo = $_GET["codigo"];

function isChecked($index)
{
    global $diagnostico;
    if (isset($diagnostico[$index]))
        return "checked='checked'";
    return '';
}

function GetSelected($query)
{
    $array;
    $result = mysql_query($query);
    if ($result)
    {
        for ($i = 0; $i < mysql_num_rows($result); $i++)
        {
            $ret[mysql_result($result, $i)] = true;
        }
        return isset($ret) ? $ret : false;
    }
    else
        return false;
}

$diagnostico = null;
$titulo = "Descripci&oacute;n Microsc&oacute;pica";

include('menu.php');
if (isset($_SESSION["protocolo"]))
{
    if (is_numeric($_SESSION["protocolo"]))
    {
        $protocolo = $_SESSION["protocolo"];
        $pap = GetSQLFirstValue("select id_pap from pap where numero_protocolo = " . $protocolo);
        if ($pap)
        {
            $diagnostico = GetSelected("select id_desc_microscopica from  pap_desc_microscopica where id_pap = " . $pap);
        }
    }
}
$query = "select codigo from template_pap_desc_microscopica group by codigo order by codigo";
?>
<script type="text/javascript">
    $(function(){
<? if (isset($protocolo))
{ ?>
            $(".step fieldset").append("<div class='save'><a href='#' class='saveButton'><img alt='guardar' title='Guardar' src='imagenes/guardar.png'/></a></div>");
<? } ?>
        $('input[type=checkbox]:visible:first').focus();    
<? if (is_numeric($step))
{ ?>
            $("#stepNumber").val("<?= $step ?>");
<? } ?>
        $(".step").hide();
        $("#step"+$("#stepNumber").val()).show();
        $(".stepButton").click(function(){
            $("#stepNumber").val($(this).val());
            $(".step").hide();
            $("#step"+$("#stepNumber").val()).show();
            $('input[type=checkbox]:visible:first').focus();
        });

        $("#templateButton").click(function(){
            $("#formulario").load("cargaTemplateDescMicroscopica.php?codigo=" + $("#plantilla").val(), function(){
                $(".step").hide();
                $("#step"+$("#stepNumber").val()).show();                
            });
        });
<? if (isset($protocolo))
{ ?>
                
            $("#formulario").ajaxStop(function(){
                $(".step fieldset").append("<div class='save'><a href='#' class='saveButton'><img alt='guardar' title='Guardar' src='imagenes/guardar.png'/></a></div>");
            });
<? } ?>
        $(".saveButton").live("click", function(event){
            $("#formPap").submit();
            event.preventDefault();
        });
    });
</script>
</head>
<body>
    <div class="pageContainer">
        <div id="steps">
            <button title="Evaluación de la muestra COLPO-CITOLÓGICA" class="stepButton" value="1" type="button">1</button>
            <button title="Agente Microbiológico identificable" class="stepButton" value="2" type="button">2</button>
            <button title="Descripción" class="stepButton" value="3" type="button">3</button>
            Protocolo: <?= $numeroProtocolo . " - " . $tipoInforme ?>
        </div>
        <form id="formPap" action="guardaDescMicroscopica.php" method="post">
            <input type="hidden" name="stepNumber" id="stepNumber" value="1" />
            <? include 'includes/inputPlantilla.php' ?>
            <div id="formulario">
                <?
                include "papStep1.php";
                include "papStep2.php";
                include "papStep3.php";
                ?>
            </div>

        </form>
    </div>
</body>
</html>